<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: json  JSON   (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">

	<div id="hd">
        <a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
        <h3>json&nbsp; <span class="subtitle">2.6.0</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_json.html">json</a>
                 &gt; JSON 
                
            </p>


	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form name="yui-classopts-form">
    <span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
    <span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
    <span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
            </form>

                    <h2>
                        

                        <code>static</code>
                        
                            Class <b>JSON</b>
                        <span class="extends">
                        </span>

                        <span class="extends">
                        </span>
                        
                        </code>
                    </h2>
                    <!-- class tree goes here -->
                    
                
  

                    <div class="summary description">
                        Provides methods to parse JSON strings and convert objects to JSON strings.
                    </div>


                        <div class="section field details">
                            <h3 id="properties">Properties</h3>
                            <div class="content">
                                    <div class="private">
                                    <h4><a name="property__BRACKETS">_BRACKETS</a>
                                        <code>- private static {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Third step in the validation.  Regex used to remove all open square
brackets following a colon, comma, or at the beginning of the string.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__CHARS">_CHARS</a>
                                        <code>- private static {Object}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Character substitution map for common escapes and special characters.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__ESCAPES">_ESCAPES</a>
                                        <code>- private static {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            First step in the validation.  Regex used to replace all escape
sequences (i.e. "\\", etc) with '@' characters (a non-JSON character).
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__INVALID">_INVALID</a>
                                        <code>- private static {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Final step in the validation.  Regex used to test the string left after
all previous replacements for invalid characters.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__SPECIAL_CHARS">_SPECIAL_CHARS</a>
                                        <code>- private static {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Regex used to replace special characters in strings for JSON
stringification.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__UNICODE_EXCEPTIONS">_UNICODE_EXCEPTIONS</a>
                                        <code>- private {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Replace certain Unicode characters that JavaScript may handle incorrectly
during eval--either by deleting them or treating them as line
endings--with escape sequences.
IMPORTANT NOTE: This regex will be used to modify the input if a match is
found.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4><a name="property__VALUES">_VALUES</a>
                                        <code>- private static {RegExp}</code>
                                    </h4>
                                    <div class="detail">
                                        <div class="description">
                                            Second step in the validation.  Regex used to replace all simple
values with ']' characters.
                                        </div>
                                    </div>
     
                                        


                                    <hr />
                                    </div>


                            </div>
                        </div>


                        <div class="section method details">
                            <h3 id="methods">Methods</h3>
                            <div class="content">
                                    <div class="">
                                    <h4>
                                        <a name="method__char">_char</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                        
                                        
                                        String
                                            <strong>_char</strong>
                                           (
                                                
                                                        
                                                         c
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Escapes a special character to a safe Unicode representation
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>c &lt;String&gt;</code>
                                                              single character to escape
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        String
                                                    </code></dt>
                                                    <dd>safe Unicode escape</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method__isValid">_isValid</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                         static 
                                        
                                        boolean
                                            <strong>_isValid</strong>
                                           (
                                                
                                                        
                                                         str
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Four step determination whether a string is valid JSON.  In three steps,
escape sequences, safe values, and properly placed open square brackets
are replaced with placeholders or removed.  Then in the final step, the
result of all these replacements is checked for invalid characters.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>str &lt;String&gt;</code>
                                                              JSON string to be tested
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        boolean
                                                    </code></dt>
                                                    <dd>is the string safe for eval?</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4>
                                        <a name="method__prepare">_prepare</a></h4>
                                    <div class="detail">
                                        <code>
                                         private 
                                        
                                        
                                        String
                                            <strong>_prepare</strong>
                                           (
                                                
                                                        
                                                         s
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Replace certain Unicode characters that may be handled incorrectly by
some browser implementations.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>s &lt;String&gt;</code>
                                                              parse input
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        String
                                                    </code></dt>
                                                    <dd>sanitized JSON string ready to be validated/parsed</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4>
                                        <a name="method__revive">_revive</a></h4>
                                    <div class="detail">
                                        <code>
                                         private 
                                        
                                        
                                        MIXED
                                            <strong>_revive</strong>
                                           (
                                                
                                                        
                                                         data
                                                    
                                                
                                                        , 
                                                         reviver
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Traverses nested objects, applying a filter or reviver function to
each value.  The value returned from the function will replace the
original value in the key:value pair.  If the value returned is
undefined, the key will be omitted from the returned object.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>data &lt;MIXED&gt;</code>
                                                              Any JavaScript data
                                                        </dd>
                                                        <dd>
                                                            <code>reviver &lt;Function&gt;</code>
                                                              filter or mutation function
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        MIXED
                                                    </code></dt>
                                                    <dd>The results of the filtered/mutated data structure</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="private">
                                    <h4>
                                        <a name="method__string">_string</a></h4>
                                    <div class="detail">
                                        <code>
                                         private 
                                        
                                        
                                        String
                                            <strong>_string</strong>
                                           (
                                                
                                                        
                                                         s
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Enclose escaped strings in quotes
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>s &lt;String&gt;</code>
                                                              string to wrap
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        String
                                                    </code></dt>
                                                    <dd>'"'+s+'"' after s has had special characters escaped</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method__stringify">_stringify</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                        
                                        
                                        String
                                            <strong>_stringify</strong>
                                           (
                                                
                                                        
                                                         h
                                                    
                                                
                                                        , 
                                                         key
                                                    
                                                
                                                        , 
                                                         depth
                                                    
                                                
                                                        , 
                                                         w
                                                    
                                                
                                                        , 
                                                         pstack
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Worker function used by public stringify.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>h &lt;Object&gt;</code>
                                                              object holding the key
                                                        </dd>
                                                        <dd>
                                                            <code>key &lt;String&gt;</code>
                                                              String key in object h to serialize
                                                        </dd>
                                                        <dd>
                                                            <code>depth &lt;Number&gt;</code>
                                                              depth to serialize
                                                        </dd>
                                                        <dd>
                                                            <code>w &lt;Array|Function&gt;</code>
                                                              array of whitelisted keys OR replacer function
                                                        </dd>
                                                        <dd>
                                                            <code>pstack &lt;Array&gt;</code>
                                                              used to protect against recursion
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        String
                                                    </code></dt>
                                                    <dd>serialized version of o</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method_dateToString">dateToString</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                         static 
                                        
                                        String
                                            <strong>dateToString</strong>
                                           (
                                                
                                                        
                                                         d
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Serializes a Date instance as a UTC date string.  Used internally by
stringify.  Override this method if you need Dates serialized in a
different format.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>d &lt;Date&gt;</code>
                                                              The Date to serialize
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        String
                                                    </code></dt>
                                                    <dd>stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method_isValid">isValid</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                         static 
                                        
                                        boolean
                                            <strong>isValid</strong>
                                           (
                                                
                                                        
                                                         str
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Four step determination whether a string is valid JSON.  In three steps,
escape sequences, safe values, and properly placed open square brackets
are replaced with placeholders or removed.  Then in the final step, the
result of all these replacements is checked for invalid characters.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>str &lt;String&gt;</code>
                                                              JSON string to be tested
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        boolean
                                                    </code></dt>
                                                    <dd>is the string safe for eval?</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method_parse">parse</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                         static 
                                        
                                        MIXED
                                            <strong>parse</strong>
                                           (
                                                
                                                        
                                                         s
                                                    
                                                
                                                        , 
                                                         reviver
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Parse a JSON string, returning the native JavaScript representation.
Only minor modifications from http://www.json.org/json2.js.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>s &lt;string&gt;</code>
                                                              JSON string data
                                                        </dd>
                                                        <dd>
                                                            <code>reviver &lt;function&gt;</code>
                                                              (optional) function(k,v) passed each key:value
pair of object literals, allowing pruning or altering values
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        MIXED
                                                    </code></dt>
                                                    <dd>the native JavaScript representation of the JSON string</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method_stringify">stringify</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                         static 
                                        
                                        string
                                            <strong>stringify</strong>
                                           (
                                                
                                                        
                                                         o
                                                    
                                                
                                                        , 
                                                         w
                                                    
                                                
                                                        , 
                                                         d
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Converts an arbitrary value to a JSON string representation.
Cyclical object or array references are replaced with null.
If a whitelist is provided, only matching object keys will be included.
If a depth limit is provided, objects and arrays at that depth will
be stringified as empty.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>o &lt;MIXED&gt;</code>
                                                              any arbitrary object to convert to JSON string
                                                        </dd>
                                                        <dd>
                                                            <code>w &lt;Array|Function&gt;</code>
                                                              (optional) whitelist of acceptable object keys to include OR a function(value,key) to alter values before serialization
                                                        </dd>
                                                        <dd>
                                                            <code>d &lt;number&gt;</code>
                                                              (optional) depth limit to recurse objects/arrays (practical minimum 1)
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        string
                                                    </code></dt>
                                                    <dd>JSON string representation of the input</dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                                    <div class="">
                                    <h4>
                                        <a name="method_stringToDate">stringToDate</a></h4>
                                    <div class="detail">
                                        <code>
                                        
                                        
                                        
                                        Date
                                            <strong>stringToDate</strong>
                                           (
                                                
                                                        
                                                         str
                                                    
                                                
                                            )
                                        </code>
                                        
                                        <div class="description">
                                            Reconstitute Date instances from the default JSON UTC serialization.
Reference this from a reviver function to rebuild Dates during the
parse operation.
                                        </div>

                                        <div class="description">

                                                <dl>
                                                    <dt>Parameters:</dt>
                                                        <dd>
                                                            <code>str &lt;String&gt;</code>
                                                              String serialization of a Date
                                                        </dd>
                                                </dl>

                                                <dl>
                                                    <dt>Returns:
                                                    <code>
                                                        Date
                                                    </code></dt>
                                                    <dd></dd>
                                                </dl>


             

                                        </div>

                                    </div>
                                    <hr />
                                    </div>
                            </div>
                        </div>







			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class=""><a href="module_animation.html">animation</a></li>

                                <li class=""><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_carousel.html">carousel</a></li>

                                <li class=""><a href="module_charts.html">charts</a></li>

                                <li class=""><a href="module_colorpicker.html">colorpicker</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_cookie.html">cookie</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_editor.html">editor</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_get.html">get</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_imagecropper.html">imagecropper</a></li>

                                <li class=""><a href="module_imageloader.html">imageloader</a></li>

                                <li class="selected"><a href="module_json.html">json</a></li>

                                <li class=""><a href="module_layout.html">layout</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_paginator.html">paginator</a></li>

                                <li class=""><a href="module_profiler.html">profiler</a></li>

                                <li class=""><a href="module_profilerviewer.html">profilerviewer</a></li>

                                <li class=""><a href="module_resize.html">resize</a></li>

                                <li class=""><a href="module_selector.html">selector</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class=""><a href="module_treeview.html">treeview</a></li>

                                <li class=""><a href="module_uploader.html">uploader</a></li>

                                <li class=""><a href="module_yahoo.html">yahoo</a></li>

                                <li class=""><a href="module_yuiloader.html">yuiloader</a></li>

                                <li class=""><a href="module_yuitest.html">yuitest</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class="selected"><a href="JSON.html">JSON</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="JSON.js.html">JSON.js</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Properties</h4>
                        <ul class="content">        
                                <li class="private"><a href="#property__BRACKETS">_BRACKETS</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__CHARS">_CHARS</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__ESCAPES">_ESCAPES</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__INVALID">_INVALID</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__SPECIAL_CHARS">_SPECIAL_CHARS</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__UNICODE_EXCEPTIONS">_UNICODE_EXCEPTIONS</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                                <li class="private"><a href="#property__VALUES">_VALUES</a>
                                        <!--<code>&lt;{RegExp}&gt;</code>-->
                                </li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Methods</h4>
                        <ul class="content">        
                                <li class=""><!--<code>String</code>-->
                                <a href="#method__char">_char</a>
                                </li>
                                <li class=""><!--<code>boolean</code>-->
                                <a href="#method__isValid">_isValid</a>
                                </li>
                                <li class="private"><!--<code>String</code>-->
                                <a href="#method__prepare">_prepare</a>
                                </li>
                                <li class="private"><!--<code>MIXED</code>-->
                                <a href="#method__revive">_revive</a>
                                </li>
                                <li class="private"><!--<code>String</code>-->
                                <a href="#method__string">_string</a>
                                </li>
                                <li class=""><!--<code>String</code>-->
                                <a href="#method__stringify">_stringify</a>
                                </li>
                                <li class=""><!--<code>String</code>-->
                                <a href="#method_dateToString">dateToString</a>
                                </li>
                                <li class=""><!--<code>boolean</code>-->
                                <a href="#method_isValid">isValid</a>
                                </li>
                                <li class=""><!--<code>MIXED</code>-->
                                <a href="#method_parse">parse</a>
                                </li>
                                <li class=""><!--<code>string</code>-->
                                <a href="#method_stringify">stringify</a>
                                </li>
                                <li class=""><!--<code>Date</code>-->
                                <a href="#method_stringToDate">stringToDate</a>
                                </li>
                        </ul>
                    </div>



            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
